package com.example.desarollo;

import com.example.desarollo.AddUsuario.asynclogin;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Principal extends Activity{
	public String user, useraux;
	TextView txt_usr, logoff;
	Button micuenta;
	private EditText segundos;
	public void onCreate(Bundle savedInstanceState) {
		 
	       super.onCreate(savedInstanceState);
	       setContentView(R.layout.principal);
         
	        txt_usr= (TextView) findViewById(R.id.usr_name);
	        segundos = (EditText) findViewById(R.id.txtsegundos);
         
         Bundle extras = getIntent().getExtras();
         //Obtenemos datos enviados en el intent.
         if (extras != null) {
      	   user  = extras.getString("user");//usuario
      	   useraux=user;
         }else{
      	   user="error";
      	   }
         
         txt_usr.setText(user);//cambiamos texto al nombre del usuario logueado
	 	             
         micuenta= (Button) findViewById(R.id.btnmicuenta);
         micuenta.setOnClickListener(new View.OnClickListener(){
	            
	        	public void onClick(View view){
	        		 
	        		Intent i = new Intent(Principal.this,Cuenta.class);
					// Closing all previous activities
					//i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
					i.putExtra("user",useraux);
					startActivity(i);
	        		
	        	}
	        													});
         
	 }
	
	 public void creaAlarma(View view) {
	    	AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
	    	Intent intent = new Intent(this, AlarmReceiver.class);
	    	PendingIntent alarmPendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);

	    	int milisegs = Integer.parseInt(segundos.getText().toString()) * 1000;
	    	
	    	alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + milisegs, alarmPendingIntent);    	
	    	
	    }
	
	
}
